<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>margin百分比</title>
</head>
<style>
    .outer{
        width:400px;
        height:300px;
        background-color:gray;
    }

    .inner1{
        width:100px;
        height:100px;
        background-color: pink;
        /* 负值表示会往相应的方向上移动相应的距离 */
        margin-top: -20%;  
    }

    .inner2{
        width:100px;
        height:100px;
        background-color: blanchedalmond;
        /* 80px = 400 * 20% */
        margin-top: 20%;   
        margin-left: -20%;
    }
</style>
<body>
    <div class="outer">
        <div class="inner1"></div>
        <div class="inner2"></div>
    </div>
</body>
</html>